package com.top10.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.top10.bean.PageBean;
import com.top10.bean.ResponseBean;
import com.top10.common.Const;
import com.top10.entity.GoodsClass;
import com.top10.service.IGoodsClassGoodsService;
import com.top10.service.IGoodsClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author sny
 * @Package com.top10.controller.mobile
 * @date 2018/10/14
 */
@RestController
@RequestMapping("/top10/goodsclass")
public class GoodsClassController {
    @Autowired
    private IGoodsClassService iGoodsClassService;

    @Autowired
    private IGoodsClassGoodsService iGoodsClassGoodsService;

    @PostMapping("/shopcategory")
    public ResponseBean selectshopcategory(String shopuuid){

        if(shopuuid==null){
            return ResponseBean.createError("shopuuid不能为空");
        }

        List<GoodsClass> shopcategory=iGoodsClassService.selectList(new EntityWrapper<GoodsClass>().eq("shop_uuid",shopuuid)
                                                                                                   .eq("isdeleted", Const.IsNotDelete));
        return ResponseBean.createSuccess().addData("shopcategory",shopcategory);

    }

    @PostMapping("goodlistbycategory")

    public ResponseBean selectgoodbycategory(String categoryuuid, String shopuuid, PageBean pageBean){

        if(shopuuid==null){
            return ResponseBean.createError("shopuuid不能为空");

        }
         Page page= PageHelper.startPage(pageBean.getPageNum(),pageBean.getPageSize());
         List<Map<String,Object>> goodslist=iGoodsClassService.selectgoodsbycategory(categoryuuid,shopuuid);

         pageBean=new PageBean(page.getPageNum(),pageBean.getPageSize(), (int) page.getTotal());

       return ResponseBean.createSuccess().addData("goodslist",goodslist).addData("pageBean",pageBean);
    }

}
